﻿package mortal.game.view.vip.panel
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.controls.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class VipComparePanel extends GSprite
    {
        private var _vipCompaireBtn:GTextFiled;
        private var _privilegeList:GTileList;
        private var _selectBg:ScaleBitmap;

        public function VipComparePanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.VipCompareTabBg, 8, 165, this));
            var _loc_1:* = GlobalStyle.textFormatItemGreen.center();
            _loc_1.size = 13;
            _loc_1.underline = true;
            this._privilegeList = UIFactory.tileList(9, 200, 890, 396, this);
            this._privilegeList.columnWidth = 870;
            this._privilegeList.rowHeight = 36;
            this._privilegeList.horizontalGap = 0;
            this._privilegeList.verticalGap = 0;
            this._privilegeList.isShowVerticalScrollBar = true;
            this._privilegeList.verticalScrollPolicy = ScrollPolicy.ON;
            this._privilegeList.direction = ScrollBarDirection.VERTICAL;
            this._privilegeList.setStyle("cellRenderer", VipCompareRender);
            this._privilegeList.dataProvider = this.getDataProvider();
            this._privilegeList.selectable = false;
            this._privilegeList.drawNow();
            this._vipCompaireBtn = UIFactory.gTextField(Language.getString(35582), 551, 126, 150, 40, this, _loc_1);
            this._vipCompaireBtn.configEventListener(MouseEvent.CLICK, this.changePrivilegeShow);
            this._selectBg = UIFactory.bg(0, 165, 75, 432, this, ImagesConst.VipCurrentBg);
            this.updateSelectPos();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._vipCompaireBtn.dispose(param1);
            this._vipCompaireBtn = null;
            this._privilegeList.dispose(param1);
            this._privilegeList = null;
            this._selectBg.dispose(param1);
            this._selectBg = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function getDataProvider() : DataProvider
        {
            var _loc_4:TVip = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = VipConfig.instance.vipDic;
            var _loc_3:Array = [];
            for each (_loc_4 in _loc_2)
            {
                
                if (_loc_4.showType >= 0)
                {
                    _loc_6 = {tvip:_loc_4};
                    _loc_3.push(_loc_6);
                }
            }
            _loc_3.sort(this.sortType);
            while (_loc_5 < _loc_3.length)
            {
                
                _loc_3[_loc_5].index = _loc_1.length;
                _loc_1.addItem(_loc_3[_loc_5]);
                _loc_5++;
            }
            return _loc_1;
        }// end function

        private function sortType(param1:Object, param2:Object) : int
        {
            if (param1.tvip.showType > param2.tvip.showType)
            {
                return 1;
            }
            if (param1.tvip.showType < param2.tvip.showType)
            {
                return -1;
            }
            if (param1.tvip.type > param2.tvip.type)
            {
                return 1;
            }
            return -1;
        }// end function

        private function changePrivilegeShow(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.VipWinChangeTab, 1));
            return;
        }// end function

        public function updateSelectPos() : void
        {
            if (Cache.instance.vip.level > 0)
            {
                this._selectBg.visible = true;
                this._selectBg.x = Cache.instance.vip.level * 75 + 57;
            }
            else
            {
                this._selectBg.visible = false;
            }
            return;
        }// end function

    }
}
